
var api = require('../../utils/api.js');
var app = getApp();
var WxParse = require('../../wxParse/wxParse.js');
Page({
    data: {
        tophe:0,
        info:[]
    },
    currentPageNumber: 1,
        onLoad() {
        var file=api.FIlE;
        this.setData({
            bg:file
        })
       this.getinfobyid();
       this.getusrinfo();
    },
    back(){
        wx.navigateBack()
    },
    onShow() {
        let jn = wx.getMenuButtonBoundingClientRect();

        console.log(jn);
        var tophe=jn.top+jn.height+80;
        this.setData({
            tophe:tophe+'px',
            over:jn.top
        })
     
    },
      // 获取详情
      getinfobyid(id){
        var that=this;
        api.post({
            url: 'index/getaddress',
            data: {id:3},
            success: data => {

                that.setData({
                    htmlSnip:that.formatRichText(data.data.content)
                })
                // 使用WxParse解析富文本内容
                if (data.data && data.data.content) {
                    WxParse.wxParse('article', 'html', data.data.content, that, 5);
                }
            },
        });
    },

    getusrinfo(){
        var that=this;
        api.post({
            url: 'user/index',
            data: {},
            success: data => {
                // 使用WxParse解析富文本内容
                that.setData({
                    user:data.data
                })
            },
        });
    },
    gohouse(){

        var info=this.data.info;


        wx.openLocation({
          latitude: parseFloat(info.lat), // 纬度
          longitude: parseFloat(info.lng), // 经度
          name: '金牛宾馆', // 位置名称
          scale: 28, // 缩放比例
          success: function () {
            console.log('地图打开成功');
          },
          fail: function (err) {
            console.error('地图打开失败', err);
          }
        });


    },
    formatRichText(html) {
        //控制小程序中图片大小
        let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {
            console.log(match.search(/style=/gi));
            if (match.search(/style=/gi) == -1) {
                match = match.replace(/\<img/gi, '<img style=""');
            }
            return match;
        });

        newContent = newContent.replace(/style="/gi, '$& max-width:100% !important; ');
        newContent = newContent.replace(/<br[^>]*\/>/gi, '');
        return newContent;
    },

});
